package com.alks.function.controller.procurement;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.RoleCheck;
import com.alks.common.aop.WebLogger;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.dto.procurement.SummaryALLDataDto;
import com.alks.function.data.request.procurement.SummaryRequest;
import com.alks.function.service.procurement.SummaryOperationService;
import com.google.zxing.WriterException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@ApiRestController("/SummaryOperation")
@Slf4j
@Api(value = "材料汇总作业", tags = {"采购部-材料汇总作业","后门接口"})
@RoleCheck(prgIds = {"150101","150203"})
public class SummaryOperationController {

    @Autowired
    private SummaryOperationService summaryOperationService;

    @WebLogger
    @PostMapping("/getNotSummaryLotNoList")
    @ApiOperation(value = "待汇总指令：查询",tags = "采购部-材料汇总作业")
    public ResponseInfo getNotSummaryLotNoList(@RequestBody SummaryRequest request){
        return summaryOperationService.getNotSummaryLotNoList(request);
    }
    @WebLogger
    @PostMapping("/getSummaryNumberList")
    @ApiOperation(value = "汇总号查询-0",tags = "采购部-材料汇总作业")
    public ResponseInfo getSummaryNumberList(@RequestBody SummaryRequest request){
        return summaryOperationService.getSummaryNumberList(request);
    }

    @WebLogger
    @PostMapping("/getSummaryLotNoList")
    @ApiOperation(value = "汇总指令查询-1",tags = "采购部-材料汇总作业")
    public ResponseInfo getSummaryLotNoList(@RequestBody SummaryRequest request){
        return summaryOperationService.getSummaryLotNoList(request);
    }

    @WebLogger
    @PostMapping("/getSummaryMaterialList")
    @ApiOperation(value = "汇总材料查询-2",tags = "采购部-材料汇总作业")
    public ResponseInfo getSummaryMaterialList(@RequestBody SummaryRequest request){
        return summaryOperationService.getSummaryMaterialList(request);
    }

    @WebLogger
    @PostMapping("/getSummaryDetailList")
    @ApiOperation(value = "汇总指令材料明细查询-3",tags = "采购部-材料汇总作业")
    public ResponseInfo getSummaryDetailList(@RequestBody SummaryRequest request){
        return summaryOperationService.getSummaryDetailList(request);
    }

    @WebLogger
    @PostMapping("/getBondingSubmaterial")
    @ApiOperation(value = "贴合子材料查询-4",tags = "采购部-材料汇总作业")
    public ResponseInfo getBondingSubmaterial(@RequestBody SummaryRequest request){
        return summaryOperationService.getBondingSubmaterial(request);
    }

    @WebLogger
    @GetMapping("/getDeleteLotNoList")
    @ApiOperation(value = "删除指令资料查询",tags = "采购部-材料汇总作业")
    public ResponseInfo getDeleteLotNoList(){
        return summaryOperationService.getDeleteLotNoList();
    }

    @WebLogger
    @PostMapping("/recoverLotNo")
    @ApiOperation(value = "删除指令资料查询：恢复指令",tags = "采购部-材料汇总作业")
    public ResponseInfo recoverLotNo(@RequestParam String lotNo){
        return summaryOperationService.recoverLotNo(lotNo);
    }

    @WebLogger
    @PostMapping("/deleteNotSummaryLotNo")
    @ApiOperation(value = "不汇总指令删除",tags = "采购部-材料汇总作业")
    public ResponseInfo deleteNotSummaryLotNo(@RequestParam String lotNo){
        return summaryOperationService.deleteNotSummaryLotNo(lotNo);
    }

    @WebLogger
    @PostMapping("/deleteSummaryLotNo")
    @ApiOperation(value = "删除汇总",tags = "采购部-材料汇总作业")
    public ResponseInfo deleteSummaryLotNo(@RequestParam String sumNo){
        return summaryOperationService.deleteSummaryLotNo(sumNo);
    }

    @WebLogger
    @PostMapping("/summaryOperation")
    @ApiOperation(value = "汇总作业",tags = "采购部-材料汇总作业")
    public ResponseInfo summaryOperation(@RequestBody SummaryALLDataDto request){
        return summaryOperationService.summaryOperation(request);
    }


    @WebLogger
    @PostMapping("/summaryOperationBatch")
    @ApiOperation(value = "汇总作业:批量",tags = "采购部-材料汇总作业")
    public ResponseInfo summaryOperationBatch(@RequestBody List<SummaryALLDataDto> request){
        return summaryOperationService.summaryOperationBatch(request);
    }

    @WebLogger
    @PostMapping("/exportSummaryMaterialDetail")
    @ApiOperation(value = "导出汇总材料明细",tags = "采购部-材料汇总作业")
    public void exportSummaryMaterialDetail(@RequestBody List<String> sumNo, HttpServletResponse response) throws IOException {
        summaryOperationService.exportSummaryMaterialDetail(sumNo,response);
    }


    @WebLogger
    @GetMapping("/cleanNoSummaryData")
    @ApiOperation(value = "采购汇总作业（按钮）：根据指令数据清洗( PC_LOT_USAGE 和 SD_BOM_FIT_SUB 和 PC_LOT_USAGE_FIT)",tags = "后门接口")
    public ResponseInfo cleanNoSummaryData(@RequestParam String lotNo){
        return summaryOperationService.cleanNoSummaryData(lotNo);
    }

    @WebLogger
    @PostMapping("/cleanNoSummaryDataBatch2")
    @ApiOperation(value = "采购汇总作业（按钮）：根据指令数据清洗( PC_LOT_USAGE 和 SD_BOM_FIT_SUB 和 PC_LOT_USAGE_FIT)-批量",tags = "后门接口")
    public ResponseInfo cleanNoSummaryDataBatch2(@RequestBody List<String> lotNos){
        return summaryOperationService.cleanNoSummaryDataBatch2(lotNos);
    }

    @WebLogger
    @PostMapping("/cleanNoSummaryDataBatch")
    @ApiOperation(value = "采购汇总作业：根据指令数据清洗( PC_LOT_USAGE 和 SD_BOM_FIT_SUB )-批量",tags = "后门接口")
    public ResponseInfo cleanNoSummaryDataBatch(@RequestBody List<String> request){
        return summaryOperationService.cleanNoSummaryDataBatch(request);
    }

    @WebLogger
    @GetMapping("/cleanNoSummaryData2")
    @ApiOperation(value = "采购汇总作业：单独清洗(SD_BOM_FIT_SUB)",tags = "后门接口")
    public ResponseInfo cleanNoSummaryData2(){
        return summaryOperationService.cleanNoSummaryData2();
    }

    @WebLogger
    @GetMapping("/cleanNoSummaryData3")
    @ApiOperation(value = "采购汇总作业：单独清洗(YF_BOM_FIT_SUB)",tags = "后门接口")
    public ResponseInfo cleanNoSummaryData3(){
        return summaryOperationService.cleanNoSummaryData3();
    }

    @WebLogger
    @GetMapping("/cleanNoSummaryData4")
    @ApiOperation(value = "采购请购：清洗差异数据(PC_LOT_USAGE_FIT_CHG和PC_LOT_USAGE_CHG和MP_PUR_DIS)",tags = "后门接口")
    public ResponseInfo cleanNoSummaryData4(@RequestParam(required = false) String lotNo){
        return summaryOperationService.cleanNoSummaryData4(lotNo);
    }

    @WebLogger
    @GetMapping("/cleanNoSummaryData5")
    @ApiOperation(value = "采购请购：清洗汇总订单表（MP_PUR_DIS和pc042)",tags = "后门接口")
    public ResponseInfo cleanNoSummaryData5(@RequestParam String lotNo){
        return summaryOperationService.cleanNoSummaryData5(lotNo);
    }

//    @WebLogger
//    @PostMapping("/summaryDataExchange")
//    @ApiOperation(value = "采购汇总作业：数据平移",tags = "采购部-材料汇总作业")
//    public ResponseInfo summaryDataExchange(@RequestParam String lotNo){
//        return summaryOperationService.summaryDataExchange(lotNo);
//    }

    @WebLogger
    @PostMapping("/summaryDataExchange2")
    @ApiOperation(value = "采购汇总作业：数据平移",tags = "后门接口")
    public ResponseInfo summaryDataExchange2(@RequestParam String lotNo){
        return summaryOperationService.summaryDataExchange2(lotNo);
    }

    @WebLogger
    @PostMapping("/summaryDataExchange3")
    @ApiOperation(value = "采购汇总作业：数据平移-批量",tags = "后门接口")
    public ResponseInfo summaryDataExchange3(@RequestBody List<String> list){
        return summaryOperationService.summaryDataExchange3(list);
    }

//    @WebLogger
//    @PostMapping("/summaryDataExchange3")
//    @ApiOperation(value = "采购汇总作业：数据平移3",tags = "后门接口")
//    public ResponseInfo summaryDataExchange3(@RequestParam String lotNo){
//        return summaryOperationService.summaryDataExchange3(lotNo);
//    }
}
